/// 参与者审核请求模型
/// 对应接口: POST /activities/participants/review/
class ParticipantReviewRequest {
  /// 活动ID（必填）
  final int activityId;
  
  /// 用户ID（必填）
  final int userId;
  
  /// 审核状态（必填）：'approved'（通过）或'rejected'（拒绝）
  final String reviewStatus;
  
  /// 审核备注（可选）
  final String? reviewNote;
  
  /// 时间戳（必填，用于AES加密）
  final String timestamp;

  ParticipantReviewRequest({
    required this.activityId,
    required this.userId,
    required this.reviewStatus,
    this.reviewNote,
    required this.timestamp,
  });

  /// 转换为JSON（用于API请求）
  /// 🎯 参数格式严格按照MyApplication2项目实现
  Map<String, dynamic> toJson() {
    // 🔄 状态映射：将英文状态转换为中文状态
    String chineseStatus;
    switch (reviewStatus.toLowerCase()) {
      case 'approved':
        chineseStatus = '通过';
        break;
      case 'rejected':
        chineseStatus = '未通过';
        break;
      default:
        chineseStatus = reviewStatus; // 如果已经是中文，保持不变
    }
    
    return {
      'activityId': activityId.toString(), // 🎯 使用驼峰命名，与MyApplication2保持一致
      'userId': userId.toString(), // 🎯 使用驼峰命名
      'reviewStatus': chineseStatus, // 🎯 使用中文状态："通过"/"未通过"
      'timestamp': timestamp,
      // 🎯 不包含reviewNote字段，MyApplication2项目中没有这个参数
    };
  }

  /// 从JSON创建实例
  factory ParticipantReviewRequest.fromJson(Map<String, dynamic> json) {
    return ParticipantReviewRequest(
      activityId: json['activity_id'] is String 
          ? int.parse(json['activity_id']) 
          : json['activity_id'],
      userId: json['user_id'] is String 
          ? int.parse(json['user_id']) 
          : json['user_id'],
      reviewStatus: json['review_status'] ?? '',
      reviewNote: json['review_note'],
      timestamp: json['timestamp'] ?? '',
    );
  }

  /// 创建通过审核的请求
  factory ParticipantReviewRequest.approve({
    required int activityId,
    required int userId,
    String? note,
  }) {
    return ParticipantReviewRequest(
      activityId: activityId,
      userId: userId,
      reviewStatus: 'approved',
      reviewNote: note,
      timestamp: (DateTime.now().millisecondsSinceEpoch ~/ 1000).toString(),
    );
  }

  /// 创建拒绝审核的请求
  factory ParticipantReviewRequest.reject({
    required int activityId,
    required int userId,
    String? note,
  }) {
    return ParticipantReviewRequest(
      activityId: activityId,
      userId: userId,
      reviewStatus: 'rejected',
      reviewNote: note,
      timestamp: (DateTime.now().millisecondsSinceEpoch ~/ 1000).toString(),
    );
  }

  @override
  String toString() {
    return 'ParticipantReviewRequest{activityId: $activityId, userId: $userId, reviewStatus: $reviewStatus, reviewNote: $reviewNote, timestamp: $timestamp}';
  }
}
